package com.sfzy.controller;

import com.sfzy.Service.MyNoticeService;
import com.sfzy.entity.MyNotice;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("myNotice")
public class MyNoticeController {
    @Autowired
    private MyNoticeService myNoticeService;

    @PostMapping
    public R add(@RequestBody MyNotice myNotice) {
        return R.ok(myNoticeService.addMyNotice(myNotice));
    }

    @PutMapping
    public R update(@RequestBody MyNotice myNotice) {
        return R.ok(myNoticeService.updateMyNotice(myNotice));
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") int id) {
        return R.ok(myNoticeService.deleteMyNotice(id));
    }

    @GetMapping("{id}")
    public R getMyNotice(@PathVariable("id") int id) {
        return R.ok(myNoticeService.getMyNotice(id));
    }

    @GetMapping("page")
    public R getMyNoticePage(MyNotice myNotice,
                             @RequestParam(defaultValue = "1",required = false) int pageNum,
                             @RequestParam(defaultValue = "6",required = false) int pageSize) {
        return R.ok(myNoticeService.getMyNoticesByPage(myNotice, pageNum, pageSize));
    }
}
